package thread;

public class MyPrintABC1 {

    volatile static int next;

    static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            while (true) {
                while (next == 0) {
                    System.out.print("A");
                    next = 1;
                }
            }
        }).start();

        new Thread(() -> {
            while (true) {
                while (next == 1) {
                    System.out.print("B");
                    next++;
                }
            }
        }).start();

        new Thread(() -> {
            while (true) {
                while (next == 2) {
                    System.out.print("C");
                    next = 0;
                }
            }
        }).start();

        Thread.sleep(30000L);
    }
}